<?php
	if (!defined("CLASS_DB_INC")) {
		define ("CLASS_DB_INC",1,1);

//		$db_access["svoptik"]["host"] = "rdbms.strato.de";
//		$db_access["svoptik"]["uid"]  = "U515825";
//		$db_access["svoptik"]["pass"] = "DRAN3a9J";
//		$db_access["svoptik"]["db"]   = "DB515825";
		$db_access["svoptik"]["host"] = "localhost";
		$db_access["svoptik"]["uid"]  = "root";
		$db_access["svoptik"]["pass"] = "";
		$db_access["svoptik"]["db"]   = "DB515825";

        class db {
			var $host      		= "";
			var $database  		= "";
			var $userid    		= "";
			var $password  		= "";
			var $id        		= 0;
			var $connected 		= false;
			var $rs          	= "";
			var $result      	= "";
			var $lastins_id		= 0;
			//================================================================

			function db($dbstring) {  // constructor
				global $db_access;
				$this->host     = $db_access[$dbstring]["host"];
				$this->database = $db_access[$dbstring]["db"];
				$this->userid   = $db_access[$dbstring]["uid"];
				$this->password = $db_access[$dbstring]["pass"];
			}

			function connect() { // Connects to defined Database
				if (!$this->connected) {
					$this->id = @mysql_connect($this->host, $this->userid, $this->password);
					if ($this->id)
						if (($this->database != "") && @mysql_select_db($this->database,$this->id))
							$this->connected = true;
				}
			}

			function doSQL($statement) { // sends an SQL-Statement
				if (!$this->connected)
					$this->connect();
				
				if ($this->connected) {
					$this->rs = @mysql_query($statement,$this->id);
					if (strtoupper(substr($statement,0,6)) == "INSERT") {
						$this->lastins_id = @mysql_insert_id($this->id);
						if ($this->lastins_id == 0) {
							@mysql_query("SELECT LAST_INSERT_ID() as lid",$this->id);
							$temp = @mysql_fetch_array($this->rs);
							$this->lastins_id = $temp["lid"];
						}
					}
					else
						$this->lastins_id = 0;
					return $this->rs;
				}
				else return false;
			}

			function readRecordset($statement) { // returns the array, needs an SQL-Statement
				if ($this->result = $this->doSQL($statement))
					return @mysql_fetch_array($this->result);
				else return false;
			}

			function getRecordset($result) { // fetches the acutal values at pointer
				return @mysql_fetch_array($result);
			}

			function flushTable($table) { // Deletes all elements in a table
				$this->rs = $this->doSQL("DELETE FROM $table");
				return $this->rs;
			}

			function resetResult($result) { // Sets the internal result count to 0
				@mysql_data_seek($result,0);
			}

            function countRows($result) { // Number of result rows
				return @mysql_num_rows($result);
			}

            function freeResult($result) { // flushes result
				return mysql_free_result($result);
			}

            function getFieldnames($result) { // Gets Fieldnames from MySQL-SELECT-Statement
				$count = $this->countRows($result);
                for ($i=0;$i<$count;$i++) {
				    $array[$i] = @mysql_field_name($result, $i);
                }
                return $array;
			}
        } // class database
	} // if !defined
?>
